﻿using System.Windows.Controls;
using EduAssess.Views;

namespace EduAssess.Services;

public class PageNavigationService
{
    private readonly Stack<Type> _pages = new();
    public Action<Page> OnPageChanged = null!;
    public bool CanGoBack => _pages.Skip(1).Any();

    public void Navigate(Page page)
    {
        OnPageChanged.Invoke(page);
        _pages.Push(page.GetType());
    }

    public void ToStartPage()
    {
        _pages.Clear();
        Navigate(new StartPage());
    }

    public void GoBack()
    {
        _pages.Pop();
        OnPageChanged.Invoke((Page)Activator.CreateInstance(_pages.Peek())!);
    }
}